package org.itheima.controller;


import org.itheima.service.LogsService;
import org.itheima.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class LogsController {

    @Autowired
    private LogsService logsService;


    @PostMapping("/addLog")
    public void addLog(@RequestBody Map<String,String> request){
        Map<String,Object> map = ThreadLocalUtil.get();
        int user_id = (int) map.get("id");
        System.out.println(user_id);
        String operate = request.get("operate");
        System.out.println(operate);
        logsService.insertLogs(user_id,operate);
    }

    @GetMapping("/logs")
    public List<Map<String,Object>> ViewTheLogs(){
        return logsService.ViewTheLogs();
    }

}
